# -*- coding: utf-8 -*-
import time

from PageClass.boe_WithholdingAmortizationClass.Class_WithholdingAmortizationBoe import Class_WithholdingAmortizationBoe
from TestCases.common import LoginDepend
from TestCases.common._baseClass import _BaseClass
from Util import config, logger, record, util


class BoeSubmit(_BaseClass):

    def __init__(self, isExit=True):
        self.isExit = isExit
        self.login = LoginDepend('basHost', 'user')
        self.WithholdingAmortization = Class_WithholdingAmortizationBoe(self.login.driver)

    def __exit__(self, *args):
        if super().__exit__(*args):
            if self.isExit:
                self.exit()
        else:
            self.exit()

    def exit(self):
        self.WithholdingAmortization.driver.quit()

    def submit(self, boe_data):
        logger.info(f"业务报账地址为：{config.urlDict.url.basHost}")  # .\Config\test\UrlConfig.yml
        # 打开预提申请单填单界面
        self.WithholdingAmortization.open_boe(boe_data.boeType)
        time.sleep(5)
        # 获取单号
        boeNo = self.WithholdingAmortization.getBoeNum()
        record.writeDataToRecord({'boeNo': boeNo, 'boeType': boe_data.boeType})  # 业务报账的单据必须传入单据类型，以便于找到"待我处理""我的单据"等菜单
        # 主表区-业务类型  # lov选择框
        self.WithholdingAmortization.input_operationType(boe_data.operationType)
        # 主表区-备注
        self.WithholdingAmortization.input_boeAbstract(boe_data.boeAbstract)
        # 主表附加区-客商  # smallTable
        self.WithholdingAmortization.input_vendor2(boe_data.vendorName)
        # 主表附加区-预提规则
        self.WithholdingAmortization.input_rule(boe_data.ruleName)

        # 费用区-预提类型,num:行数
        self.WithholdingAmortization.input_operationSubType(boe_data.operationSubTypeName)
        # 费用区-责任部门,num:行数
        self.WithholdingAmortization.input_expenseDept(boe_data.expenseDeptCode)
        # 费用区-金额,num:行数
        self.WithholdingAmortization.input_expenseAmount(boe_data.itemamount)
        # 费用区-开始日期,选当天,num:行数
        self.WithholdingAmortization.input_beginDate()
        # 费用区控件:右移
        self.WithholdingAmortization.find_scrollToRight()
        # 费用区-期限（月）
        self.WithholdingAmortization.input_deadline(boe_data.deadline)
        # 费用区-贷方科目
        self.WithholdingAmortization.input_accountId(boe_data.accountCode)
        # 费用区-费用行-自动计算 # 确认计算结果
        self.WithholdingAmortization.click_autocalcu()

        # # 保存单据
        # self.WithholdingAmortization.click_boeSaveButton()
        # time.sleep(5)
        # 提交单据
        message = self.WithholdingAmortization.click_boeSubmitButton()
        return message
